import { Promise } from 'drunk-base';
import { observable, computed } from 'mobx';
import { getMedia, updateMedia, createMedia } from './MediaHttpResource';
import * as Validator from '../../../service/Validator';
import { Validate, ItemModel, IItemProps } from '../../ItemModel';

export interface IMediaModel extends IItemProps {
    name: string;
    wxMpName: string;
    wxMpId: string;
    contactInfo: string;
    note: string;
}

export class MediaModel extends ItemModel<IMediaModel> {

    @observable data: IMediaModel = {
        name: "",
        wxMpId: "",
        wxMpName: "",
        contactInfo: "",
        note: "",
    };

    @Validate("请输入媒体名称")
    @computed get nameValid() { return this.data && Validator.notEmpty(this.data.name) }

    @Validate("请输入公众号微信ID")
    @computed get wxMpIdValid() { return this.data && Validator.notEmpty(this.data.wxMpId) }

    @Validate("请输入公众号名称")
    @computed get wxMpNameValid() { return this.data && Validator.notEmpty(this.data.wxMpName) }

    @Validate(`请输入联系方式`)
    @computed get contactInfoValid() { return this.data && Validator.notEmpty(this.data.contactInfo) }

    @Validate(`请输入备注信息`)
    @computed get noteValid() { return this.data && Validator.notEmpty(this.data.note) }
    

    createItemImpl(data: IMediaModel) {
        return createMedia(data);
    }

    fetchItemImpl(id: string) {
        return getMedia(id);
    }

    updateItemImpl(id: string, data: IMediaModel) {
        return updateMedia(id, data);
    }
}